<template>
    <div style="background-color:white">
      <el-table v-loading="loading" stripe border :data="resultList" @selection-change="handleSelectionChange" :height="tableHeight"  :header-cell-style="handerMethod">
        <!-- <el-table-column type="selection" width="55" align="center"></el-table-column> :formatter="nameFormat" -->
        <el-table-column label="上传时间" align="center" prop="upDate" ></el-table-column>
        <el-table-column label="归属表" align="center" prop="belong" ></el-table-column>
        <el-table-column label="归属信息项" align="center" prop="itemInfo" ></el-table-column>
        <el-table-column label="文件名" align="center" prop="fileNameReal" ></el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-download" @click="handleDownload(scope.row)"
            >下载
            </el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                  @pagination="getList"/>
    </div>
  </template>

  <script>
  import {
    delUploadInfo,
    getUploadInfo, listUploadInfo
  } from '@/api/app/carbonEmission/uploadInfo'
  // import { getToken } from "@/utils/auth";

  import {delExportHisData} from  '@/api/app/carbonEmission/assist'

  export default {
    components: '',
    data() {
      return {
        timer1: null,
        // 查询参数
        queryParams: {
          date: this.moment().format('YYYY-MM-DD'),


          pageNum: 1,
          pageSize: 10,
        },
        // 遮罩层
        loading: false,
        // 选中数组
        ids: [],
        tableHeight: this.tableHeight,
        // 总条数
        total: 0,
        resultList: [],

      }
    },
    created() {
      this.init()
      this.getList()
    },
    mounted() {
      this.tableHeight = (window.innerHeight - 270)  + "px"; //260即表格之外的固定高度

      window.onresize = () => {
        return (() => {
          this.tableHeight = (window.innerHeight -270)  + "px";

        })();
      };
    },
    destroyed() {
      if (this.timer1) clearInterval(this.timer1)
    },
    methods: {
      init() {
        this.timer1 = setInterval(() => {
          this.getList()
        }, 30000)
      },
      toggleTab(tab, event) {
        // if (tab.name == 'tab2') {
        //   this.getOList()
        //   this.tab2Name = 'tab2'
        // } else if (tab.name == 'tab3') {
        //   this.getTList()
        //   this.tab2Name = 'tab3'
        // }
      },
      /** 查询导出的文件列表 */
      getList() {
        this.loading = true
        // getExportHisDataList(this.queryParams).then(res => {
        //   this.resultList = res.data.rows
        //   this.total = res.data.total
        //   this.loading = false
        //   console.log(this.resultList)
        // })
        listUploadInfo(this.queryParams).then(res => {
              this.resultList = res.data.rows
              this.total = res.data.total
              this.loading = false

            })

      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        this.$confirm('是否确认删除?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          return delUploadInfo(row.id)
        }).then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        })
      },

      handleDeleteIds(row) {
        const ids = row.fileName || this.ids
        this.$confirm('是否确认删除?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          // return delExportHisData(ids)
          return delUploadInfo(row.id)
        }).then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        })
      },
      /** 下载按钮操作 */
      handleDownload(row) {
        this.$confirm('是否确认下载?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // this.download(row.fileName,"furnaceExport",false)
          this.download(row.filePath,false)
          this.msgSuccess('下载成功')

        })
      },
      nameFormat(row){
        let name = row.fileName
        const parts = name.split(/_/, 3); // 分割成两部分，以第一个下划线为分隔
        return parts.length > 2 ? parts[1] +'_' + parts[2]: name;
      },
        handerMethod({ row, column, rowIndex, columnIndex }) {
            // console.log(row, column, rowIndex, columnIndex)
            // if (rowIndex === 0) {//行索引为0代表表头那一行
            //   if (columnIndex === 1) {//列索引，找到你自己要合并的那一列，这个是动态的，根据实际需求来
            //     this.$nextTick(() => {
            //       if (document.getElementsByClassName(column.id).length !== 0) {
            //         document.getElementsByClassName(column.id)[0].setAttribute('colSpan', 2)
            //       }
            //     })
            //   }
            // }
            // if (rowIndex === 0 && columnIndex ===2) {//将相邻的列设为隐藏
            //   return { display: 'none' }
            // }
            return { background: '#b1defd', color: '#606266', fontWeight: '800', textAlign: 'center' }
        },
    }
  }
  </script>
